<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*
      promise.all和promise.race的区别
      all是全部成功才返回成功
      race是第一个成功就返回成功的那个，失败就返回失败
    */
    let p1 = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve('01')
      }, 2000)
    })
    let p2 = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve('02')
      }, 1000)
    })
    let p3 = new Promise((resolve, reject) => {
      resolve('网络不好,请求超时')
      // reject('1')
    })
    let pAll = Promise.race([p1, p2, p3])
    pAll.then((res) => {
      console.log(res);
    }, (reason) => {
      console.log(reason);
    })
    console.log(pAll);
    //使用场景--请求超时
    //谁先执行完返回谁
  </script>
</body>

</html>